package com.hytc.mymall.frgament;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.hytc.mymall.R;
import com.hytc.mymall.adapter.HomePageAdapter;
import com.hytc.mymall.adapter.HomePageHeaderAdapter;
import com.hytc.mymall.bean.MerchantConsumptionBean;
import com.hytc.mymall.bean.NoticeBean;
import com.hytc.mymall.bean.UnionConsumptionBean;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by allkiss on 2016/12/9
 */

public class HomePageFragment extends Fragment {
    private View header;
    private ListView lv;
    private ListView ptrlv;

    private List<MerchantConsumptionBean> getData1() {
        final ArrayList<MerchantConsumptionBean> list = new ArrayList<MerchantConsumptionBean>();
        final MerchantConsumptionBean merchantConsumptionBean = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e021", "10000");
        final MerchantConsumptionBean merchantConsumptionBean2 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e022", "10000");
        final MerchantConsumptionBean merchantConsumptionBean3 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e023", "10000");
        final MerchantConsumptionBean merchantConsumptionBean4 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e024", "10000");
        final MerchantConsumptionBean merchantConsumptionBean5 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e025", "10000");
        final MerchantConsumptionBean merchantConsumptionBean6 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e026", "10000");
        final MerchantConsumptionBean merchantConsumptionBean7 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e027", "10000");
        final MerchantConsumptionBean merchantConsumptionBean8 = new MerchantConsumptionBean("\u6210\u90fdxxx\u8d85\u5e028", "10000");
        list.add(merchantConsumptionBean);
        list.add(merchantConsumptionBean2);
        list.add(merchantConsumptionBean3);
        list.add(merchantConsumptionBean4);
        list.add(merchantConsumptionBean5);
        list.add(merchantConsumptionBean6);
        list.add(merchantConsumptionBean7);
        list.add(merchantConsumptionBean8);
        return list;
    }

    private List<NoticeBean> getData2() {
        final ArrayList<NoticeBean> list = new ArrayList<NoticeBean>();
        final NoticeBean noticeBean = new NoticeBean("\u6210\u90fdxxx\u8d85\u5e02\u52a0\u5165\u4e00\u70b9\u516c\u76ca");
        final NoticeBean noticeBean2 = new NoticeBean("\u6210\u90fdxxx\u8d85\u5e02\u52a0\u5165\u4e00\u70b9\u516c\u76ca2");
        final NoticeBean noticeBean3 = new NoticeBean("\u6210\u90fdxxx\u8d85\u5e02\u52a0\u5165\u4e00\u70b9\u516c\u76ca3");
        final NoticeBean noticeBean4 = new NoticeBean("\u6210\u90fdxxx\u8d85\u5e02\u52a0\u5165\u4e00\u70b9\u516c\u76ca4");
        list.add(noticeBean);
        list.add(noticeBean2);
        list.add(noticeBean3);
        list.add(noticeBean4);
        return list;
    }

    private List<UnionConsumptionBean> getData3() {
        final ArrayList<UnionConsumptionBean> list = new ArrayList<UnionConsumptionBean>();
        final UnionConsumptionBean unionConsumptionBean = new UnionConsumptionBean("6%", "100000", "200");
        final UnionConsumptionBean unionConsumptionBean2 = new UnionConsumptionBean("12%", "250000", "500");
        final UnionConsumptionBean unionConsumptionBean3 = new UnionConsumptionBean("24", "100000", "200");
        list.add(unionConsumptionBean);
        list.add(unionConsumptionBean2);
        list.add(unionConsumptionBean3);
        return list;
    }

    private void initData() {
        this.lv.setAdapter((ListAdapter) new HomePageHeaderAdapter((Context) this.getActivity(), this.getData3()));
        final HomePageAdapter adapter = new HomePageAdapter((Context) this.getActivity(), this.getData1(), this.getData2());
//        this.ptrlv.getRefreshableView().setDividerHeight(1);
//        if (this.ptrlv.getRefreshableView().getHeaderViewsCount() < 1) {
//            this.ptrlv.getRefreshableView().addHeaderView(this.header);
//        }
//        this.ptrlv.getRefreshableView().setAdapter((ListAdapter) adapter);
    }

    private void initView(final View view) {
        final TextView textView = (TextView)view.findViewById(R.id.toolbar_title);
        this.ptrlv = (ListView) view.findViewById(R.id.toolbar_title);
        this.lv = (ListView)this.header.findViewById(R.id.ptrlv_homepage);
        final TextView textView2 = (TextView)this.header.findViewById(2131100313);
        textView.setText((CharSequence)this.getResources().getString(2131361837));
        textView2.setVisibility(View.GONE);
    }

    @Override
    public View onCreateView(final LayoutInflater layoutInflater, final ViewGroup viewGroup, final Bundle bundle) {
        this.header = layoutInflater.inflate(2130903195, (ViewGroup)null);
        return layoutInflater.inflate(R.layout.fragment_homepage, viewGroup, false);
    }

    @Override
    public void onViewCreated(final View view, final Bundle bundle) {
        super.onViewCreated(view, bundle);
        this.initView(view);
        this.initData();
    }
}
